package com.kuangjia.student_ems.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Table(name = "users")
@TableName("users")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = com.baomidou.mybatisplus.annotation.IdType.AUTO)
    private Long id;
    
    @Column(nullable = false, unique = true)
    private String username;
    
    @Column(nullable = false)
    @JsonIgnore
    private String password;
    
    @Column(nullable = false)
    private String name;
    
    private String email;
    
    private String phone;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private UserRole role;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "department_id")
    @TableField(exist = false)
    private Department department;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "position_id")
    @TableField(exist = false)
    private Position position;
    
    @TableField("department_id")
    @Column(name = "department_id", insertable = false, updatable = false)
    private Long departmentId;

    @TableField("position_id")
    @Column(name = "position_id", insertable = false, updatable = false)
    private Long positionId;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private EmployeeStatus status = EmployeeStatus.ACTIVE;
    
    @Column(name = "entry_date")
    private LocalDate entryDate;
    
    @Column(name = "leave_date")
    private LocalDate leaveDate;
    
    @Column(name = "leave_reason")
    private String leaveReason;
    
    @CreationTimestamp
    private LocalDateTime createTime;
    
    @UpdateTimestamp
    private LocalDateTime updateTime;
    
    public enum UserRole {
        EMPLOYEE, // 普通员工
        DEPARTMENT_MANAGER, // 部门管理人员
        HR_ADMIN // 企业人事
    }
    
    public enum EmployeeStatus {
        ACTIVE, // 在职
        LEFT    // 离职
    }
} 